//
//  EveryTenSongsTableViewCell.m
//  LuckyRadio
//
//  Created by Mr、J on 15/11/17.
//  Copyright © 2015年 chenjun. All rights reserved.
//

#import "EveryTenSongsTableViewCell.h"
#import "CustomerNetworking.h"
#import <UIImageView+WebCache.h>
#import "SongListModel.h"
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

#define WIDTH_PRO(X) (X)*(SCREEN_WIDTH/375)

#define HEIGHT_PRO(Y) (Y)*(SCREEN_HEIGHT/667)

@implementation EveryTenSongsTableViewCell
- (void)dealloc
{
    [_contentLabel release];
    [_image release];
    [_songsPageModel release];
    [_titleLabel release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self createSubViews];
        
        [self loadData];
        
        
    }
    return self;
}

-(void)createSubViews
{
    self.titleLabel = [UILabel new];
    [self.contentView addSubview:self.titleLabel];
    [_titleLabel release];
    
    self.image = [UIImageView new];
    [self.contentView addSubview:self.image];
    [_image release];
    
    self.contentLabel = [UILabel new];
    self.contentLabel.textColor = [UIColor grayColor];
    self.contentLabel.font = [UIFont systemFontOfSize:15];
    self.contentLabel.numberOfLines = 0;
    [self.contentView addSubview:self.contentLabel];
    [_contentLabel release];
    
    
}

-(void)loadData
{
    self.dataArray = [NSMutableArray array];
    [CustomerNetworking customerWithURL:@"http://api.dongting.com/frontpage/frontpage?location=0&version=1447252806&app=ttpod&v=v8.1.1.2015110616&user_id=0&mid=iPhone5S&f=f234&s=s310&imsi=&hid=&splus=8.4.1&active=1&net=2&openudid=e97c1f17f916efa173065a10152c7506e65b60f7&idfa=5FBD2BF5-1484-4C9B-A138-4D9CE22EADB5&utdid=VkKezJUW5SwDAGga0yzrZnyO&alf=700606&bundle_id=com.ttpod.music&latitude=38.89679373280231&longtitude=121.5286730881665" andParamer:nil andBlock:^(id response) {
        
        NSDictionary *Dic = [[[[response objectForKey:@"data"] objectAtIndex:10] objectForKey:@"data"] objectAtIndex:0];
        SongListModel *songListModel = [SongListModel modelWithDictionary:Dic];
        [self.image sd_setImageWithURL:[NSURL URLWithString:songListModel.picUrl]];
        self.contentLabel.text = songListModel.desc;
        
        }];

}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.image.frame = CGRectMake(WIDTH_PRO(10), HEIGHT_PRO(40), (SCREEN_WIDTH - WIDTH_PRO(40)) / 3, (SCREEN_WIDTH - WIDTH_PRO(40)) / 3);
    self.titleLabel.frame = CGRectMake(WIDTH_PRO(10), HEIGHT_PRO(10), SCREEN_WIDTH - WIDTH_PRO(20), HEIGHT_PRO(20));
    self.contentLabel.frame = CGRectMake(self.image.frame.origin.x + self.image.frame.size.width + WIDTH_PRO(10), self.image.frame.origin.y, SCREEN_WIDTH - self.image.frame.size.width - WIDTH_PRO(30), HEIGHT_PRO(100));
}

-(void)setSongsPageModel:(SongsPageModel *)songsPageModel
{
    if (_songsPageModel != songsPageModel) {
        [_songsPageModel release];
        _songsPageModel = [songsPageModel retain];
    }
    
    self.titleLabel.text = songsPageModel.name;
}

+(EveryTenSongsTableViewCell *)everyTenSongsTableViewCellWith:(UITableView *)tableView
{
    static NSString *cellIdentifier = @"everyTenSongs";
    EveryTenSongsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[EveryTenSongsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
